package org.ailoli.aixiang.base

import androidx.lifecycle.Lifecycle
import autodispose2.AutoDispose
import autodispose2.AutoDisposeConverter
import autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider


abstract class BaseMvpFragment<T : BasePresenter<*>?> : BaseFragment(),
    BaseView {
    protected var mPresenter: T? = null
    override fun onDestroyView() {
        super.onDestroyView()
        mPresenter?.detachView()
        super.onDestroyView()
    }

    /**
     * 绑定生命周期 防止MVP内存泄漏
     *
     * @param <T>
     * @return
    </T> */
    override fun <T> bindAutoDispose(): AutoDisposeConverter<T>? {
        return AutoDispose.autoDisposable(
            AndroidLifecycleScopeProvider
                .from(this, Lifecycle.Event.ON_DESTROY)
        )
    }
}